﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;


namespace Kooboo.Commerce.Repositories
{
    [Export(typeof(ICartItem))]
    public partial class CartItem:Entity,ICartItem
    {

        #region ICartItem Members

        IProduct _product;
        IProduct ICartItem.Product
        {
            get
            {
                if(this._product == null)
                {
                    this._product = this.DataContext.Products
                        .Where(i => i.Id == this.ProductId)
                        .FirstOrDefault();
                }

                return this._product;
            }
            set
            {
                this._product = value;
                this.ProductId = value.Id;
            }
        }

        ISaleItem _saleItem;
        ISaleItem ICartItem.SaleItem
        {
            get
            {
                if (this._saleItem == null)
                {
                    this._saleItem = this.DataContext.SaleItems
                        .Where(i => i.Id == this.SaleItemId)
                        .FirstOrDefault();
                }

                return this._saleItem;
            }
            set
            {
                this._saleItem = value;
                this.SaleItemId = value.Id;
            }
        }

        List<IPromotionRule> _Promotions;
        public List<IPromotionRule> Promotions
        {
            get
            {
                if (this._Promotions == null)
                {
                    this._Promotions = new List<IPromotionRule>();
                }

                return this._Promotions;
            }
        }

        #endregion
    }
}
